package com.china.osourcechina;
import android.content.Intent;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RelativeLayout;

import com.china.base.BaseActivity;
import com.china.fragment.Comprehensivefragment;
import com.china.fragment.Foundfragment;
import com.china.fragment.Minefragment;
import com.china.fragment.Movefragment;

/**
 * Created by Administrator on 2016/5/6.
 */
public class HomeActivity extends BaseActivity implements View.OnClickListener {

    private RadioButton rb_home_comprehensive;
    private RadioButton rb_home_move;
    private ImageView iv_home_more;
    private RadioButton rb_home_mine;
    private RadioButton rb_home_found;
    private RelativeLayout lvLeftMenu;
    private DrawerLayout mDrawerLayout;
    private Toolbar toolbar;
    private ActionBarDrawerToggle mDrawerToggle;
    private FragmentManager fm;
    private FragmentTransaction ft;
    private Comprehensivefragment comprehensivefragment;
    private Movefragment movefragment;
    private Foundfragment foundfragment;
    private Minefragment minefragment;

    @Override
    protected int loadWindowLayout() {
        return R.layout.activity_home;
    }

    @Override
    protected void initTitleBar() {

    }

    @Override
    protected void initViews() {
        initview();
        fm = getSupportFragmentManager();
        ft = fm.beginTransaction();
        findViews();
        setSupportActionBar(toolbar);
        lvLeftMenu.getLayoutParams().width = getWindowManager().getDefaultDisplay().getWidth()/2;
        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.open, R.string.close);
        mDrawerToggle.syncState();
        mDrawerLayout.setDrawerListener(mDrawerToggle);
    }


    private void findViews() {
        toolbar = (Toolbar) findViewById(R.id.tl_custom);
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        lvLeftMenu = (RelativeLayout) findViewById(R.id.left_drawer);
         comprehensivefragment = new Comprehensivefragment();
         movefragment = new Movefragment();
         foundfragment = new Foundfragment();
         minefragment = new Minefragment();
        ft.replace(R.id.home_frame,comprehensivefragment);
        ft.commit();
    }

    private void initview() {
        rb_home_comprehensive = (RadioButton)findViewById(R.id.rb_home_comprehensive);
        rb_home_move = (RadioButton)findViewById(R.id.rb_home_move);
        iv_home_more = (ImageView)findViewById(R.id.iv_home_more);
        rb_home_found = (RadioButton)findViewById(R.id.rb_home_found);
        rb_home_mine = (RadioButton)findViewById(R.id.rb_home_mine);
        findViewById(R.id.answer).setOnClickListener(this);
        findViewById(R.id.software).setOnClickListener(this);
        findViewById(R.id.blog).setOnClickListener(this);
        findViewById(R.id.git).setOnClickListener(this);
        findViewById(R.id.setting).setOnClickListener(this);
        findViewById(R.id.night).setOnClickListener(this);
        rb_home_comprehensive.setOnClickListener(this);
        rb_home_move.setOnClickListener(this);
        iv_home_more.setOnClickListener(this);
        rb_home_found.setOnClickListener(this);
        rb_home_mine.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()){
            case R.id.rb_home_comprehensive:
                ft = fm.beginTransaction();
                ft.replace(R.id.home_frame,comprehensivefragment);
                ft.commit();
                break;
            case R.id.rb_home_move:
                ft = fm.beginTransaction();
                ft.replace(R.id.home_frame,movefragment);
                ft.commit();
                break;
            case R.id.iv_home_more://更多
                startActivity(new Intent(HomeActivity.this,SelectPicPopupWindow.class));
                break;
            case R.id.rb_home_found:
                ft = fm.beginTransaction();
                ft.replace(R.id.home_frame,foundfragment);
                ft.commit();
                break;
            case R.id.rb_home_mine:
                ft = fm.beginTransaction();
                ft.replace(R.id.home_frame,minefragment);
                ft.commit();
                break;
            case R.id.answer:
                Intent intent = new Intent(HomeActivity.this,DrawerActivity.class);
                intent.putExtra("title","技术问答");
                startActivity(intent);
                break;
            case R.id.software:
                Intent software = new Intent(HomeActivity.this,DrawerActivity.class);
                software.putExtra("title","开源控件");
                startActivity(software);
                break;
            case R.id.blog:
                Intent blog = new Intent(HomeActivity.this,DrawerActivity.class);
                blog.putExtra("title","博客区");
                startActivity(blog);
                break;
            case R.id.git:

                break;
            case R.id.setting:
                Intent setting = new Intent(HomeActivity.this,SettingActivity.class);
                startActivity(setting);
                break;
            case R.id.night:
                break;

        }
    }
}
